﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using System.ComponentModel;

namespace AfterlifeLib.Lighting
{
    public class Light
    {
        //TODO: Put this value in the .lvl file.
        public static float ambient = 0.3f;

        [Category("Light"), Description("The Name of the Light.")]
        private string name;
        /// <summary>
        /// The name of the light, used in the level editor.
        /// </summary>
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        [Category("Light"), Description("If the Light is enabled.")]
        private bool enabled = true;
        /// <summary>
        /// Wether the light is enabled and should be drawn.
        /// </summary>
        public bool IsEnabled
        {
            get { return enabled; }
            set { enabled = value; }
        }

        [Category("Light"), Description("The Color of the Light.")]
        private Color color;
        /// <summary>
        /// The color of the light.
        /// </summary>
        public Color Color
        {
            get { return color; }
            set { color = value; }
        }

        /// <summary>
        /// Gets the Color of the light as a Vector3
        /// </summary>
        [Browsable(false)]
        public Vector3 ColorV3
        {
            get { return color.ToVector3(); }
        }

        /// <summary>
        /// Gets the Color of the light as a Vector4
        /// </summary>
        [Browsable(false)]
        public Vector4 ColorV4
        {
            get { return color.ToVector4(); }
        }

        [Category("Light"), Description("The Radius of the Light.")]
        private float radius;
        /// <summary>
        /// Gets or sets the radius of the light.
        /// </summary>
        public float Radius
        {
            get { return radius; }
            set { radius = value; }
        }

        [Category("Light"), Description("The Strength of the Light.")]
        private float strength;
        /// <summary>
        /// Gets or sets the strength of the light (0 - 1).
        /// </summary>
        public float Strength
        {
            get { return strength; }
            set { strength = value; }
        }

        [Category("Light"), Description("The Position of the Light.")]
        private Vector3 position;
        /// <summary>
        /// Gets or sets the position of the light.
        /// </summary>
        public Vector3 Position
        {
            get { return position; }
            set { position = value; }
        }

        /// <summary>
        /// Gets the position of the light as a Vector2.
        /// </summary>
        [Browsable(false)]
        public Vector2 PositionV2
        {
            get { return new Vector2(Position.X, Position.Y); }
        }

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="name">The name of the light.</param>
        /// <param name="color">The color of the light.</param>
        /// <param name="radius">The radius of the light in pixels.</param>
        /// <param name="strength">The strength of the light (0 - 1).</param>
        /// <param name="position">The position of the light.</param>
        public Light(string name, Color color, float radius, float strength, Vector3 position)
        {
            this.name = name;
            this.color = color;
            this.radius = radius;
            this.strength = strength;
            this.position = position;
        }

        /// <summary>
        /// Method used to get the location where the light should be drawn
        /// on the screen.
        /// </summary>
        /// <param name="camera"></param>
        /// <returns></returns>
        public Vector3 GetScreenPosition(Camera2D camera)
        {
            return new Vector3(Position.X - camera.Position.X, Position.Y - camera.Position.Y, Position.Z);
        }
    }
}
